//
//  FreightDetailVC.m
//  saler-ios
//
//  Created by 王亚陆 on 17/6/7.
//  Copyright © 2017年 sayimba. All rights reserved.
//

#import "FreightDetailVC.h"
#import "PriceCell.h"
#import "TransportVC.h"
#import "HomeVC.h"
@interface FreightDetailVC ()
<
UITableViewDelegate,
UITableViewDataSource
>
{
    UIImageView * nav;
    RootViewController * TabBar;
    NSMutableArray * PriceArrData;
    UITableView * PriceTable;

}

@property (nonatomic,strong) UIView * backview;
@end

@implementation FreightDetailVC


- (instancetype)init
{
    self = [super init];
    if (self) {
        self.inforDic = [[NSMutableDictionary alloc]init];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    nav = [self createNav:@"查询结果"];
    [self.view addSubview:nav];
    
    
    UIButton * btn = [UIButton createUIbutton:@"关闭" andFont:FontOfSize13 andColor:RGBACOLOR(79, 79, 79,1)];
    [nav addSubview:btn];
    [btn addTarget:self action:@selector(pressBtn) forControlEvents:UIControlEventTouchUpInside];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(nav.mas_right).with.offset(-20*kWidth);
        make.centerY.mas_equalTo(nav.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50*kWidth, 33*kHeight));
    }];

    
    self.view.backgroundColor = UIviewBackColor;
    PriceArrData = [[NSMutableArray alloc]init];
    
//    data =     {
//        distance = "1758.23";
//        freightComplete = 2200;
//        freightUnit = "2285.7";
//        insureFee = "1.17";
//        standardComplete = 2000;
//        standardUnit = "2057.13";
//    };

    
    
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"保险费" forKey:@"name"];
    
    NSString * insure = [NSString stringWithFormat:@"%.2f元",[_inforDic[@"insureFee"] floatValue]];
    [dic setObject:insure forKey:@"money"];
    
    NSMutableDictionary * dic1 = [[NSMutableDictionary alloc]init];
    [dic1 setObject:@"里程" forKey:@"name"];
    
    NSString * distance = [NSString stringWithFormat:@"%.2f(公里)",[_inforDic[@"distance"] floatValue]];
    [dic1 setObject:distance forKey:@"money"];
    

    [PriceArrData addObject:dic];
    [PriceArrData addObject:dic1];

    
    
    [self createBackview];
    [self createBtn];
}



-(void)pressBtn{
    
    
    HomeVC * home =[[HomeVC alloc]init];
    [self.navigationController pushViewController:home animated:YES];
    
    
}

-(void)createBackview{
    
    _backview = [[UIView alloc]init];
    _backview.backgroundColor = WhiteColor;
    [self.view addSubview:_backview];
    [_backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left);
        make.top.mas_equalTo(nav.mas_bottom).with.offset(10*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 266*kHeight));
    }];
    
    UILabel * pricelabel = [UILabel createUIlabel:@"标准价格" andFont:FontOfSize14 andColor:PriceLabelColor];
    [_backview addSubview:pricelabel];
    [pricelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_backview.mas_centerX);
        make.top.mas_equalTo(_backview.mas_top).with.offset(25*kHeight);
    }];
    
    UIView * leftLine = [[UIView alloc]init];
    leftLine.backgroundColor = PriceLineColor;
    [_backview addSubview:leftLine];
    [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview.mas_left).with.offset(58*kWidth);
        make.centerY.mas_equalTo(pricelabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(91*kWidth, 0.5*kHeight));
    }];
    UIView * rightLine = [[UIView alloc]init];
    rightLine.backgroundColor = PriceLineColor;
    [_backview addSubview:rightLine];
    [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview.mas_right).with.offset(-58*kWidth);
        make.centerY.mas_equalTo(pricelabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(91*kWidth, 0.5*kHeight));
    }];
    

    
    PriceTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Main_Width, 86*kHeight) style:UITableViewStylePlain];
    PriceTable.separatorStyle =NO;
    PriceTable.userInteractionEnabled = NO;
    [PriceTable setTableFooterView:[UIView new]];
    PriceTable.delegate = self;
    PriceTable.dataSource = self;
    PriceTable.sectionIndexBackgroundColor= GrayColor;
    [_backview addSubview:PriceTable];
    [PriceTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview.mas_left);
        make.top.mas_equalTo(pricelabel.mas_bottom).with.offset(11*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 75*kHeight));
    }];
    [PriceTable reloadData];
    
    UIView * Hline1 =[[UIView alloc]init];
    Hline1.backgroundColor = GrayColor;
    [_backview addSubview:Hline1];
    [Hline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview.mas_right).with.offset(-58*kWidth);
        make.top.mas_equalTo(PriceTable.mas_bottom).with.offset(5*kHeight);
        make.size.mas_equalTo(CGSizeMake(258*kWidth, 1*kHeight));
    }];

    
    
    UILabel * unitLabel = [UILabel createUIlabel:@"单台" andFont:FontOfSize13 andColor:PriceColor];
    [_backview addSubview:unitLabel];
    [unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview.mas_left).with.offset(67*kWidth);
        make.top.mas_equalTo(PriceTable.mas_bottom).with.offset(30*kHeight);
    }];
    UIImageView * smallImage0 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"money"]];
    [_backview addSubview:smallImage0];
    
    [smallImage0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(unitLabel.mas_left).with.offset(-5*kWidth);
        make.centerY.mas_equalTo(unitLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(9*kWidth, 9*kHeight));
    }];
    
    
    UIImageView * imageUnit = [[UIImageView alloc]init];
    imageUnit.image = [UIImage imageNamed:@"jiantou"];
    [_backview addSubview:imageUnit];
    [imageUnit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(unitLabel.mas_right).with.offset(15*kWidth);
        make.centerY.mas_equalTo(unitLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(138*kWidth, 4*kHeight));
    }];
    
    NSString * freightUnit = [NSString stringWithFormat:@"%@元(运费)",_inforDic[@"freightUnit"]];
    UILabel * carriageLbel = [UILabel  createUIlabel:freightUnit andFont:FontOfSize12 andColor:PriceLabelColor];
//    [_backview addSubview:carriageLbel];
//    [carriageLbel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(imageUnit.mas_centerX);
//        make.bottom.mas_equalTo(imageUnit.mas_top);
//    }];
    
    
    NSString * standardUnit = [NSString stringWithFormat:@"%@元",_inforDic[@"standardUnit"]];

    UILabel * unitPriceLabel = [UILabel createUIlabel:standardUnit andFont:FontOfSize13 andColor:PriceColor];
    [_backview addSubview:unitPriceLabel];
    [unitPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview.mas_right).with.offset(-58*kWidth);
        make.bottom.mas_equalTo(imageUnit.mas_top);
    }];
    UILabel * standerLabel = [UILabel createUIlabel:@"标准价" andFont:FontOfSize13 andColor:YellowColor];
    [_backview addSubview:standerLabel];
    [standerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(unitPriceLabel.mas_right);
        make.top.mas_equalTo(imageUnit.mas_bottom);
    }];

    
    UILabel * BoardLabel = [UILabel createUIlabel:@"整板" andFont:FontOfSize13 andColor:PriceColor];
    [_backview addSubview:BoardLabel];
    [BoardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview.mas_left).with.offset(67*kWidth);
        make.top.mas_equalTo(unitLabel.mas_bottom).with.offset(40*kHeight);
    }];
    
    UIImageView * smallImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"money"]];
    [_backview addSubview:smallImage];
    
    [smallImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(BoardLabel.mas_left).with.offset(-5*kWidth);
        make.centerY.mas_equalTo(BoardLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(9*kWidth, 9*kHeight));
    }];

    
    
    UIImageView * imageBoard = [[UIImageView alloc]init];
    imageBoard.image = [UIImage imageNamed:@"jiantou"];
    [_backview addSubview:imageBoard];
    [imageBoard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(BoardLabel.mas_right).with.offset(15*kWidth);
        make.centerY.mas_equalTo(BoardLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(138*kWidth, 4*kHeight));
    }];
    
    NSString * freightComplete = [NSString stringWithFormat:@"%@元(运费)",_inforDic[@"freightComplete"]];

    
    UILabel * carriageLbel1 = [UILabel  createUIlabel:freightComplete andFont:FontOfSize12 andColor:PriceLabelColor];
//    [_backview addSubview:carriageLbel1];
//    [carriageLbel1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(imageBoard.mas_centerX);
//        make.bottom.mas_equalTo(imageBoard.mas_top);
//    }];
//
    
    NSString * standardComplete = [NSString stringWithFormat:@"%@元",_inforDic[@"standardComplete"]];

    UILabel * BoardPriceLabel = [UILabel createUIlabel:standardComplete andFont:FontOfSize13 andColor:PriceColor];
    [_backview addSubview:BoardPriceLabel];
    [BoardPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview.mas_right).with.offset(-58*kWidth);
        make.bottom.mas_equalTo(imageBoard.mas_top);
    }];
    UILabel * standerLabel1 = [UILabel createUIlabel:@"标准价" andFont:FontOfSize13 andColor:YellowColor];
    [_backview addSubview:standerLabel1];
    [standerLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(BoardPriceLabel.mas_right);
        make.top.mas_equalTo(imageBoard.mas_bottom);
    }];

    
    
    
    
}

-(void)createBtn{
    
    UIButton * nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [nextBtn setTitle:@"我要发车" forState:UIControlStateNormal];
    //    [nextBtn setImage:[UIImage imageNamed:@"home_next"] forState:UIControlStateNormal];
    [nextBtn setTitleColor:WhiteColor forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(pressNextBtn:) forControlEvents:UIControlEventTouchUpInside];
    nextBtn.layer.cornerRadius = 5;
    nextBtn.layer.borderWidth = 0.5;
    //    nextBtn.layer.borderColor = UIbtnColor.CGColor;
    //    nextBtn.backgroundColor = UIbtnColor;
    nextBtn.layer.borderColor = YellowColor.CGColor;
    nextBtn.backgroundColor = YellowColor;
    
    [self.view addSubview:nextBtn];
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(355*kWidth, 50*kHeight));
        make.top.mas_equalTo(_backview.mas_bottom).with.offset(37*kHeight);
    }];

    
}

-(void)pressNextBtn:(UIButton*)sender{
    
    
    TransportVC * sport = [[TransportVC alloc]init];
    
    sport.backHome = YES;
    
    [self.navigationController pushViewController:sport animated:YES];
    NSLog(@"下一步");
}


#pragma mark - 表单协议

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section{
    
    
    return PriceArrData.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    static NSString  *CellIdentifier = @"CellIdentifier";
    PriceCell * cell =  [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell ==nil) {
        cell = [[PriceCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.PriceLabel.text = [NSString stringWithFormat:@"%@",PriceArrData[indexPath.row][@"money"]];
    cell.PriceName.text = [NSString stringWithFormat:@"%@",PriceArrData[indexPath.row][@"name"]];
    
    UIImageView * endAddressImage = [[UIImageView alloc]init];
    endAddressImage.image = [UIImage imageNamed:@"home_blue"];
    [cell.contentView addSubview:endAddressImage];
    [endAddressImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(cell.PriceName.mas_left).with.offset(-5*kWidth);
        make.centerY.mas_equalTo(cell.PriceLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 6*kHeight));
    }];
    
    
    return cell;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return  33*kHeight;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
